import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:xvideos/assets_tool/images.dart';
import 'package:xvideos/hj_page/mine_business/make_money/withdrawal_page.dart';
import 'package:xvideos/hj_page/mine_business/welfare/share_data_list_page.dart';
import 'package:xvideos/hj_page/mine_business/widgets/mine_share_qr_view.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';
import 'package:xvideos/routers/jump_router.dart';
import 'package:xvideos/tools_base/global_store/store.dart';
import 'package:xvideos/tools_base/widget/net_image_widget.dart';

import '../../../config/config.dart';

class MineIncomePage extends StatefulWidget {
  const MineIncomePage({super.key});

  @override
  State<MineIncomePage> createState() => _MineIncomePageState();
}

class _MineIncomePageState extends State<MineIncomePage> {
  @override
  void initState() {
    super.initState();
    globalStore.refreshWallet();
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Container(
        padding: EdgeInsets.only(left: 10, right: 10, top: 10),
        child: Column(
          children: [
            Container(
              padding: EdgeInsets.fromLTRB(6, 23, 6, 6),
              decoration: BoxDecoration(color: Color(0xFF030F18)),
              child: Column(
                children: [
                  Consumer<GlobalStore>(
                    builder: (_, store, __) => Row(
                      children: [
                        NetworkImageLoader(
                          imageUrl: store.meInfo?.portrait ?? '',
                          width: 60,
                          height: 60,
                          borderRadius: 30,
                        ),
                        10.sizeBoxW,
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              "普通代理",
                              style: const TextStyle(color: const Color(0xFFFFFFFF), fontWeight: FontWeight.w500, fontSize: 18.0),
                            ),
                            5.sizeBoxH,
                            Text(
                              "邀请好友快速提现",
                              style: const TextStyle(color: const Color(0xff989898), fontWeight: FontWeight.w400, fontSize: 12.0),
                            )
                          ],
                        ),
                        Spacer(),
                        Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.end,
                          children: [
                            Text(
                              "可提现金额",
                              style: const TextStyle(color: const Color(0xB2FFFFFF), fontWeight: FontWeight.w500, fontSize: 12.0),
                            ),
                            SizedBox(height: 1),
                            Text(
                              "${(store.wallet?.income ?? 0) ~/ 10}",
                              style: const TextStyle(color: const Color(0xffE1351F), fontWeight: FontWeight.w500, fontSize: 24.0),
                            )
                          ],
                        )
                      ],
                    ),
                  ),
                  29.sizeBoxH,
                  Container(
                    padding: EdgeInsets.symmetric(horizontal: 10),
                    width: double.infinity,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.end,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        InkWell(
                          onTap: () => Get.to(WithdrawalPage()),
                          child: Image.asset(
                            'withdraw_now.webp'.mineImgPath,
                            width: (MediaQuery.of(context).size.width - 70) / 2,
                            height: 48,
                          ),
                        ),
                        InkWell(
                          onTap: () => Get.to(ShareDataListPage()),
                          child: Image.asset(
                            'promotional_data.webp'.mineImgPath,
                            width: (MediaQuery.of(context).size.width - 70) / 2,
                            height: 48,
                          ),
                        ),
                      ],
                    ),
                  ),
                  if (Config.proxyBannerJump?.additionalProp != null)
                    Column(
                      children: [
                        29.sizeBoxH,
                        InkWell(
                          onTap: () {
                            pushToPageByLink(Config.proxyBannerJump?.additionalProp?.url ?? "");
                          },
                          child:Config.proxyBannerJump?.additionalProp?.banner != null ?  NetworkImageLoader(
                            imageUrl: Config.proxyBannerJump?.additionalProp?.banner ?? '',
                            width: double.infinity,
                            borderRadius: 0,
                          ):Image.asset(
                            'proxy_banner.webp'.mineImgPath,
                            width: double.infinity,
                          ),
                        ),
                      ],
                    )
                ],
              ),
            ),
            12.sizeBoxH,
            Container(
              padding: EdgeInsets.symmetric(horizontal: 6, vertical: 5),
              child: Row(
                children: [
                  Text(
                    "规则说明",
                    style: const TextStyle(color: const Color(0xFFFFFFFF), fontWeight: FontWeight.bold, fontSize: 18.0),
                  ),
                ],
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5, horizontal: 0),
              width: double.infinity,
              child: RichText(
                textAlign: TextAlign.left,
                text: TextSpan(
                  style: TextStyle(fontSize: 12, color: Color(0x73FFFFFF)), // 默认样式
                  children: [
                    TextSpan(text: '1. 邀请'),
                    TextSpan(
                      text: '1名好友',
                      style: TextStyle(color: Colors.red),
                    ),
                    TextSpan(text: '成功注册即可获得1天VIP'),
                  ],
                ),
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5, horizontal: 0),
              width: double.infinity,
              child: RichText(
                textAlign: TextAlign.left,
                text: TextSpan(
                  style: TextStyle(fontSize: 12, color: Color(0x73FFFFFF)), // 默认样式
                  children: [
                    TextSpan(text: '2．邀请好友产充值可获'),
                    TextSpan(
                      text: '充值最高70％返利收益',
                      style: TextStyle(color: Colors.red),
                    ),
                  ],
                ),
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5, horizontal: 0),
              width: double.infinity,
              child: RichText(
                textAlign: TextAlign.left,
                text: TextSpan(
                  style: TextStyle(fontSize: 12, color: Color(0x73FFFFFF)), // 默认样式
                  children: [
                    TextSpan(text: '如：邀请好友A，A充值'),
                    TextSpan(
                      text: '100元年卡',
                      style: TextStyle(color: Colors.red),
                    ),
                    TextSpan(text: 'VIP,'),
                    TextSpan(
                      text: '即可获得70元收益，可提现！',
                      style: TextStyle(color: Colors.red),
                    ),
                  ],
                ),
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 5, horizontal: 0),
              width: double.infinity,
              child: RichText(
                textAlign: TextAlign.left,
                text: TextSpan(
                  style: TextStyle(fontSize: 12, color: Color(0x73FFFFFF)), // 默认样式
                  children: [
                    TextSpan(text: '邀请说明：点击【保存二维码】或【复制推广链接】分享给朋友下载即可'),
                  ],
                ),
              ),
            ),
            12.sizeBoxH,
            MineShareQRView(),
            12.sizeBoxH,
            Image.asset(
              "invite_steps.webp".mineImgPath,
              fit: BoxFit.fill,
            ),
            24.sizeBoxH,
          ],
        ),
      ),
    );
  }
}
